package dao

import (
	"ssims/models"
)

func GetAllCommon(common map[string]interface{}) (error, []models.Common, int64) {
	var commonData []models.Common
	page := common["page"].(int)
	pageSize := common["limit"].(int)
	searchId := common["searchId"].(string)
	var total int64
	err := db.Table("common").Select("z_id", "z_name", "fx_id", "fx_name").Where("z_id like ?", searchId+"%").Order("z_id ASC").Count(&total).Offset((page - 1) * pageSize).Limit(pageSize).Find(&commonData).Error
	return err, commonData, total
}

func AddCommon(common models.Common) error {
	err := db.Table("common").Select("z_id", "z_name", "fx_id", "fx_name").Create(&common).Error
	return err
}
